package org.skydiveapp;

import org.skydiveapplibrary.data.MoreCategory;
import org.skydiveapplibrary.ui.MoreCategoryAdapter;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class MoreActivity extends ListActivity
{
	// listeners
	private OnItemClickListener itemClickListener = new OnItemClickListener()
	{
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id)
		{
			// get selected category
			MoreCategoryAdapter adapter = (MoreCategoryAdapter)getListAdapter();
			MoreCategory category = (MoreCategory)adapter.getItem(position);
			// handle selection
			handleSelection(category);
		}
	};
	
	@Override 
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		// set adapter
		setListAdapter(new MoreCategoryAdapter(this));
		
		getListView().setOnItemClickListener(itemClickListener);
	}
	
	private void handleSelection(MoreCategory category)
	{
		if (category == MoreCategory.Aircraft)
		{
			Intent intent = new Intent(this, AircraftListActivity.class);
			startActivity(intent);
		}
		else if (category == MoreCategory.SkydiveTypes)
		{
			Intent intent = new Intent(this, SkydiveTypeListActivity.class);
			startActivity(intent);
		}
		else if (category == MoreCategory.Locations)
		{
			Intent intent = new Intent(this, LocationListActivity.class);
			startActivity(intent);
		}
		else if (category == MoreCategory.WingLoadCalculator)
		{
			Intent intent = new Intent(this, WingLoadCalculatorActivity.class);
			startActivity(intent);
		}
		else if (category == MoreCategory.ImportExport)
		{
			Intent intent = new Intent(this, ImportExportActivity.class);
			startActivity(intent);
		}
		else if (category == MoreCategory.Settings)
		{
			Intent intent = new Intent(this, SettingsActivity.class);
			startActivity(intent);
		}
	}
}
